import React from 'react';
import {statusIcon} from '../utils/convert';
import style from './Components.module.scss';
import {InfoCircleOutlined} from '@ant-design/icons';
import {Link} from 'react-router-dom';
import {Button, Dropdown, Menu, Typography} from 'antd';
import {SourceLogo} from './SourceLogo';

const {Text}=Typography;

export const SpiderHeader=({spider, showWarning})=>{
  return <>
    {statusIcon[spider.status]}任务 {spider.id}
    <SourceLogo source={spider.type}/>
    {
      showWarning && <>
        <Text className={style.info} type={'secondary'}>
          <InfoCircleOutlined/>{' '}
          此界面数据不会实时更新，请前往{' '}
          <Link to={'/tasks'}>爬虫任务</Link>{' '}
          页面查看最新状态
        </Text>
      </>
    }
    <Text style={{float: 'right'}} type={'secondary'}>
      {spider.created_at}
    </Text>
    <Dropdown overlay={<Menu>
      <Menu.Item key={'jd'}>
        <a target={'_blank'} href={`https://wqsou.jd.com/search/searchn?key=图书 ${spider.key}&datatype=1&page=1&pagesize=100&sceneval=2`} rel="noreferrer">
          京东搜索页
        </a>
      </Menu.Item>
      <Menu.Item key={'dd'}>
        <a target={'_blank'} href={`http://search.m.dangdang.com/search_ajax.php?action=all_search&keyword=${spider.key}&act=get_product_flow_search&page=1&cid=01.00.00.00.00.00`} rel="noreferrer">
          当当搜索页
        </a>
      </Menu.Item>
    </Menu>} key={5}><Button type={'link'}>DEBUG</Button></Dropdown>
  </>;
};
